package com.zjp.controller;

import com.zjp.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;

@Controller
public class ThymeleafController {
    @RequestMapping("/hello1")
    public String test1(Model model){
        model.addAttribute("msg", "hello1 thymeleaf");

        return "hello1";
    }
    @RequestMapping("/hello2")
    public String test2(Model model){
        User user = new User();
        user.setName("zjp");
        user.setAge(18);
        user.setFriend(new User("lxh", 18));//调用两个参数的构造方法
        user.setRole("admin");//设置用户角色

        User user1 = new User();
        user1.setName("hw");
        user1.setAge(18);
        user1.setFriend(new User("zyy", 18));

        ArrayList<User> users = new ArrayList<>();
        users.add(user);
        users.add(user1);

        model.addAttribute("user", user);//将user放入model中，传给前端调用
        model.addAttribute("users", users);//将users放入model中，传给前端调用

        return "hello2";
    }
    @RequestMapping("/hello3")
    public String test3(Model model){
        model.addAttribute("today", new Date());//日期类型

        return "hello3";
    }
}
